﻿<script type="text/javascript">
$(document).ready(function(){
   $("#btn_login_dir").click(function(event){	   
		$.ajax({
		   contentType: 'application/json',
		   type: "POST",
		   url: "/aib_login/",
		   dataType: 'html',
		   data: (function() {
						var parametros = {};
						var theForm = window.document.LoginFormDir;
						var num_of_elements = theForm.length;
						//alert(num_of_elements);
						for (var i=0; i<num_of_elements; i++){
							var theElement = theForm.elements[i];
							var element_type = theElement.type;
							var element_name = theElement.name;
							var element_value = theElement.value;
							if(element_type=="radio"){
								if (theElement.checked==true){
									parametros[element_name]=element_value;
								}
							}else{
								parametros[element_name]=element_value;
								//alert(parametros[element_name]);
							}
						}
						
						return parametros;
					})(),
		   success: function(resp) {
						var key = resp;						
						var i = 0;
						//alert(key);
						if (key.indexOf("success")>-1){
							$("#sucesso_dialog").dialog({
															position: 'center',
															modal: true,
															resizable: false,
															height: 170,
															buttons: {
																Ok: function() {
																	$(this).dialog('close');
																}
															}
														});
							//content_manager_ajax('middle_content','middle_content_info.html')
							$.ajax({
							   contentType: 'application/html',
							   type: "POST",
							   url: "/user_info/",
							   dataType: 'html',
							   success: function(resp) {
											var html_source = resp;	
											//alert(html_source);
											//$("#middle_content").html("<div class=\"main-content\">"+html_source+"</div>");
											$("#middle_content").html(html_source);
											return;	
										},
								error: function() {
									$("#erro_dialog_cadastrar").dialog({ resizable: false });
								},
							 });				
							content_manager_ajax('right_content_top','menu_dir_temp_login.html')
							content_manager_ajax('left_content_top','navigation_temp_menu_esq.html');							
							//location.href = 'complete/' //redireciona pra pagina completa
						}else if (key.indexOf("fail")>-1){
							$("#fail_dialog").dialog({
															modal: true,
															resizable: false,
															height: 170,
															buttons: {
																Ok: function() {
																	$(this).dialog('close');
																}
															}
														});
														
						}else if (key.indexOf("disable")>-1){
							$("#disable_dialog").dialog({
															modal: true,
															resizable: false,
															height: 170,
															buttons: {
																Ok: function() {
																	$(this).dialog('close');
																}
															}
														});
														
						}
						return;	
						
					},
			error: function() {
				// Prompt for user data and process the result using a callback:
				//alert('Falha de conexao com o servidor.');
				$("#erro_dialog").dialog({ resizable: false });
			},
		 });
   });
   
$("#link_logout").click(function(event){	   
		$.ajax({
		   contentType: 'application/json',
		   type: "POST",
		   url: "/aib_logout/",
		   dataType: 'html',
		   success: function(resp) {
						var key = resp;						
						var i = 0;
						//alert(key);
						if (key.indexOf("logout")>-1){
							$("#logout_dialog").dialog({
													modal: true,
													resizable: false,
													height: 170,
													buttons: {
														Ok: function() {
															$(this).dialog('close');
														}
													}
												});
							content_manager_ajax('right_content_top','menu_dir_temp_login.html');
							content_manager_ajax('middle_content','middle_content_logout.html');
							//content_manager_ajax('left_content_top','navigation_temp_menu_esq.html');							
							//location.href = '/principal/' //redireciona pra pagina completa
						}
						return;	
					},
			error: function() {
				// Prompt for user data and process the result using a callback:
				//alert('Falha de conexao com o servidor.');
				$("#erro_dialog").dialog({ resizable: false });
			},
		 });
   });   
 });
</script>
{% if user.is_authenticated %}
<div class="subcontent-unit-border" id="loginDiv">
          <div class="round-border-topleft"></div>
          <div class="round-border-topright"></div>
          <h1>Bem vindo:</h1>
          <div class="loginform">
			Cliente: {{ user.username }}
			<br/><br/>
			Sair: <a style="cursor:pointer" id="link_logout">[Clique aqui]</a>
          </div>
        </div>	
{% else %}
<div id="disable_dialog" title="Desabilitado" style="display: none; ">
<p>
<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span> 
<span style="padding-top:10px; font-size:16px;font:Verdana, Geneva, sans-serif;">Usuário não ativo.<br/>Por favor entre em contato com o suporte.
</span>
</p>
</div>

<div id="fail_dialog" title="Falha" style="display: none; ">
<p>
<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span> 
<span style="padding-top:10px; font-size:16px;font:Verdana, Geneva, sans-serif;">Usuário ou senha incorretos.<br/>Insira usuário e senha corretos e tente novamente.
</span>
</p>
</div>

<div id="sucesso_dialog" title="Sucesso" style="display: none; ">
<p>
<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span> 
<span style="padding-top:10px; font-size:16px;font:Verdana, Geneva, sans-serif;">Login feito com sucesso.<br/>Bem vindo!
</span>
</p>
</div>

<div id="erro_dialog" title="Erro" style="display: none; ">
	<p>Falha na conexao com o servidor.</p>
</div>
<div class="subcontent-unit-border-green" id="loginDiv">
          <div class="round-border-topleft"></div>
          <div class="round-border-topright"></div>
          <h1 class="green">Área do Cliente</h1>
          <div class="loginform">
            <form action="" method="post" id="LoginFormDir" name="LoginFormDir">
              <p>
                <input type="hidden" name="rememberme" value="0" />
              </p>
              <fieldset>
                <p>
                  <label for="username" class="top">Usuário:</label>
                  <br />
                  <input name="username" type="text" class="field" id="id_username" tabindex="1" value="" maxlength="30" />
                </p>
                <p>
                  <label for="pass" class="top">Senha:</label>
                  <br />
				  <input type="hidden" name="this_is_the_login_form" value="1" />
                  <input name="password" type="password" class="field" id="id_password" tabindex="2" value="" maxlength="10" />
                </p>
                <p>
                  <input type="checkbox" name="checkbox" id="checkbox" class="checkbox" tabindex="3" size="1" value=""/>
                  <label for="checkbox_1" class="right">Lembre-me</label>
                </p>
                <p>
                  <input type="button" name="btn_login_dir" class="button" value=" Entrar " id="btn_login_dir"  />
                </p>
                <p><a href="#" onclick="webLoginShowForm(2);return false;" id="forgotpsswd_2">Esqueceu a senha?</a></p>
              </fieldset>
            </form>
          </div>
        </div>
{% endif %}

